<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
	</head>
	<body>
		<h1 id="h1">你好，hello,12.。</h1>
		<div><span id="num">0</span>个字符</div>
		<script type="text/javascript">
			function checkLen(str) {
			  //先把中文替换成两个字节的英文，在计算长度
			  return str.replace(/[\u0391-\uFFE5]/g,"aa").length;  
			}
			var str = document.getElementById("h1").innerText
			var len = checkLen(str)
			document.getElementById('num').innerHTML=len
		</script>
	</body>
</html>
